package com.assessment.config;

import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 微信企业号配置
 */
@Configuration
public class WxCpConfig {

    @Value("${wechat.cp.corp-id}")
    private String corpId;

    @Value("${wechat.cp.corp-secret}")
    private String corpSecret;

    @Value("${wechat.cp.agent-id}")
    private Integer agentId;

    @Value("${wechat.cp.token}")
    private String token;

    @Value("${wechat.cp.aes-key}")
    private String aesKey;

    @Bean
    public WxCpService wxCpService() {
        WxCpDefaultConfigImpl config = new WxCpDefaultConfigImpl();
        config.setCorpId(corpId);
        config.setCorpSecret(corpSecret);
        config.setAgentId(agentId);
        config.setToken(token);
        config.setAesKey(aesKey);

        WxCpService wxCpService = new WxCpServiceImpl();
        wxCpService.setWxCpConfigStorage(config);
        return wxCpService;
    }
}
